package com.anlogic.sdk.startup.utils;

import java.io.File;
import java.io.IOException;

import com.anlogic.sdk.utils.EnvUtils;
import com.anlogic.sdk.utils.FileUtils;
import com.anlogic.sdk.utils.ProcLauncher;

public class Utils {
	public static final String PROGRAM = EnvUtils.getIDERootPath() + "/tools/license_check/license_verify" + EnvUtils.getExcuteExtend();
	public static final String LICENSE = EnvUtils.getIDERootPath() + "/tools/license_check/license.lic";
	
	public static boolean licenseExeExists() {
		boolean ret = true;
		if (!(new File(PROGRAM)).exists()) {
			ret = false;
		}
		return ret;
	}
	
	public static boolean licenseExists() {
		boolean ret = true;
		if (!(new File(LICENSE)).exists()) {
			ret = false;
		}
		return ret;
	}
	
	public static String getCommand() {
		return PROGRAM + " " + LICENSE;
	}
	
	public static String getLicenseContent() {
		String licenseContent = FileUtils.read(new File(LICENSE));
		return licenseContent;
	}
	
	public static void replaceLicense(String newFile) throws IOException {
		FileUtils.copyFile(new File(newFile), new File(LICENSE));
	}
	
	public static String validate() {
		ProcLauncher proc = new ProcLauncher();
		String ret = proc.launch(getCommand());
		return ret;
	}
}
